<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <th:block th:include="include :: header('立项申请新增')"/>
</head>
<body class="pear-container" onload="start()">

<form class="layui-form" action=""  th:object="${ApplyProject}">

	<h4 align="center" style="font-size: large">项目基本信息</h4><br>
<div class="layui-card">
	<div class="layui-card-body">

							<div class="layui-form-item layui-hide">
								<label class="layui-form-label">id</label>
								<div class="layui-input-block">
									<input id="proId" type="text" th:value="*{id}" name="proId" lay-verify="title"
										   autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
			                    <label class="layui-form-label">项目编号</label>
			                    <div class="layui-input-inline">
			                        <input readonly th:value="*{proNumber}" type="text" name="proNumber" autocomplete="off" placeholder="项目编号" class="layui-input">
			                    </div>

								<label class="layui-form-label">学科分类</label>
								<div class="layui-input-inline">
									<select id="proSubject">
										<option value="" selected>请选择学科分类</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'a'" value="a">马列社科</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'b'" value="b">党史党建</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'c'" value="c">哲学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'd'" value="d">理论经济</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'e'" value="e">应用经济</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'f'" value="f">统计学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'g'" value="g">政治学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'h'" value="h">法学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'i'" value="i">社会学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'j'" value="j">民族学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'k'" value="k">中国历史</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'l'" value="l">世界历史</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'm'" value="m">宗教学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'n'" value="n">中国文学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'o'" value="o">外国文学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'p'" value="p">语言学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'q'" value="q">新闻学与传播学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'r'" value="r">图书馆、情报与文献学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 's'" value="s">体育学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 't'" value="t">管理学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'u'" value="u">人口学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'v'" value="v">国际问题研究</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'w'" value="w">考古学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'x'" value="x">教育学</option>
										<option th:field="*{proSubject}" th:checked="*{proSubject} eq 'y'" value="y">艺术学</option>
									</select>
								</div>

								<label class="layui-form-label">项目类型</label>
								<div class="layui-input-inline">
									<select id="proType" lay-filter="firstProType">
										<option th:field="*{proType}" th:checked="*{proType} eq 'a'" value="a">新型智库项目</option>
										<option th:field="*{proType}" th:checked="*{proType} eq 'b'" value="b">省级社科联项目</option>
									</select>
								</div>

								<div class="layui-input-inline" name="selectChild" id="selectChild" lay-filter="selectChild">
									<select id="shengType" >
										<option th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq ''" value="" selected>请选择省级子项目类型</option>
										<option th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq 'c'" value="c">重大项目</option>
										<option th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq 'd'" value="d">一般项目</option>
										<option th:field="*{proTypeChild}" th:checked="*{proTypeChild} eq 'e'" value="e">青年项目</option>
									</select>
								</div>



			                </div>

							<div class="layui-form-item">
								<label class="layui-form-label">项目名称</label>
								<div class="layui-input-inline">
									<input th:value="*{proName}" type="text" name="proName" autocomplete="off" placeholder="项目名称" class="layui-input">
								</div>

			                    <label class="layui-form-label">申报单位</label>
			                    <div class="layui-input-inline">
			                        <input readonly th:value="*{proDept}" autocomplete="off" placeholder="申报单位" class="layui-input">
			                    </div>
			                </div>


</div>
</div>

<h4 align="center" style="font-size: large">课题负责人基本信息</h4><br>
<div class="layui-card">
	<div class="layui-card-body">

							<div class="layui-form-item">
			                    <label class="layui-form-label">姓名</label>
			                    <div class="layui-input-inline">
			                        <input th:value="*{manName}" type="text" name="manName" autocomplete="off" placeholder="负责人名称" class="layui-input">
			                    </div>

								<label class="layui-form-label">年龄</label>
								<div class="layui-input-inline">
									<input th:value="*{manAge}" type="text" name="manAge" autocomplete="off" placeholder="年龄" class="layui-input">

								</div>

								<label class="layui-form-label">性别</label>
								<div class="layui-input-inline">
									<input  th:field="*{manSex}" th:checked="*{manSex} eq '0'" type="radio" name="manSex" value="0" title="男">
									<input  th:field="*{manSex}" th:checked="*{manSex} eq '1'" type="radio" name="manSex" value="1" title="女">
<!--									<input th:value="*{manSex}" type="text" name="manSex" autocomplete="off" placeholder="性别" class="layui-input">-->
								</div>

								<label class="layui-form-label">民族</label>
								<div class="layui-input-inline">
									<input th:value="*{manNation}" type="text" name="manNation" autocomplete="off" placeholder="民族" class="layui-input">
								</div>

			                </div>

							<div class="layui-form-item">
			                    <label class="layui-form-label">职务</label>
			                    <div class="layui-input-inline">
			                        <input th:value="*{manOffice}" type="text" name="manOffice" autocomplete="off" placeholder="职务" class="layui-input">
			                    </div>

								<label class="layui-form-label">专业职称</label>
								<div class="layui-input-inline">
									<input th:value="*{manTitle}" type="text" name="manTitle" autocomplete="off" placeholder="职称" class="layui-input">
								</div>

								<label class="layui-form-label">研究专长</label>
								<div class="layui-input-inline">
									<input th:value="*{manExpertise}" type="text" name="manExpertise" autocomplete="off" placeholder="专长" class="layui-input">
								</div>

								<label class="layui-form-label">电话</label>
								<div class="layui-input-inline">
									<input th:value="*{manPhone}" type="text" name="manPhone" autocomplete="off" placeholder="电话" class="layui-input">
								</div>

			                </div>

							<div class="layui-form-item">
			                    <label class="layui-form-label">通讯地址</label>
			                    <div class="layui-input-inline">
			                        <input th:value="*{manAddress}" style="width: 300px" type="text" name="manAddress" autocomplete="off" placeholder="地址" class="layui-input">
			                    </div>

								<label class="layui-form-label" style="margin-left: 80px">邮政编码</label>
								<div class="layui-input-inline" >
									<input  th:value="*{manZip}" type="text" name="manZip" autocomplete="off" placeholder="邮政编码" class="layui-input">
								</div>

			                </div>

	</div>
</div>

<h4 align="center" style="font-size: large">与本课题有关的近期研究成果  <i id="ktTips" class="layui-icon layui-icon-tips" style="font-size: large"></i></h4>
<div class="layui-card">
	<div class="layui-card-body">
							<div class="layui-form-item">
			                    <label class="layui-form-label"></label>
								<div>
									<!--									<input type="text" name="proResearch" autocomplete="off" placeholder="近期研究成果" class="layui-input">-->
									<textarea th:utext="*{proResearch}" id="proResearch"  name="proResearch" style="font-size: large;border-color: #4EC9B0" cols="110" rows="10"></textarea>
								</div>
			                </div>
	</div>
</div>

<h4 align="center" style="font-size: large">课题主要参与者基本情况</h4><br>
<div class="layui-card">
	<div class="layui-card-body">

							<div class="layui-form-item layui-hide">
			                    <label class="layui-form-label">主要参与者id</label>
			                    <div class="layui-input-block">
			                        <input type="text" name="partId" autocomplete="off" placeholder="主要参与者id" class="layui-input">
			                    </div>
			                </div>

							<table id="applyParticipator-table" lay-filter="applyParticipator-table"></table>

	</div>
</div>

<h4 align="center" style="font-size: large">课题论证设计  <i id="lzTips" class="layui-icon layui-icon-tips" style="font-size: large"></i></h4>
<div class="layui-card">
	<div class="layui-card-body">
							<div class="layui-form-item">
			                    <label class="layui-form-label"></label>
								<div >
									<!--									<input type="text" name="proDesign" autocomplete="off" placeholder="课题论证设计" class="layui-input">-->
									<textarea th:utext="*{proDesign}" id="proDesign" name="proDesign" style="font-size:large;border-color: #4EC9B0" rows="30" cols="110"></textarea>
								</div>
			                </div>
	</div>
</div>


<h4 align="center" style="font-size: large">完成本课题的条件分析  <i id="tjTips" class="layui-icon layui-icon-tips" style="font-size: large"></i></h4>
<div class="layui-card">
	<div class="layui-card-body">


							<div class="layui-form-item">
			                    <label class="layui-form-label"></label>
								<div>
									<textarea th:utext="*{proAnalyse}" id="proAnalyse" style="font-size:large;border-color: #4EC9B0" name="proAnalyse" cols="110" rows="15"></textarea>
									<!--									<input type="text" name="proAnalyse" autocomplete="off" placeholder="完成条件分析" class="layui-input">-->
								</div>
			                </div>

	</div>
</div>

<h4 align="center" style="font-size: large">参加者分工情况</h4><br>
<div class="layui-card">
	<div class="layui-card-body">

							<div class="layui-form-item layui-hide">
			                    <label class="layui-form-label">分工情况id</label>
			                    <div class="layui-input-block">
			                        <input type="text" name="taskId" autocomplete="off" placeholder="分工情况id" class="layui-input">
			                    </div>
							</div>

							<table id="applyTask-table" lay-filter="applyTask-table"></table>


	</div>
</div>

<h4 align="center" style="font-size: large">经费预算</h4><br>
<div class="layui-card">
	<div class="layui-card-body">

							<div class="layui-form-item">
			                    <label class="layui-form-label">资料费(元)</label>
			                    <div class="layui-input-inline">
			                        <input th:value="*{costMart}" type="text" name="costMart" autocomplete="off" placeholder="资料费" class="layui-input">
			                    </div>

								<label class="layui-form-label">差旅费(元)</label>
								<div class="layui-input-inline">
									<input th:value="*{costTraval}" type="text" name="costTraval" autocomplete="off" placeholder="差旅费" class="layui-input">
								</div>

								<label class="layui-form-label">会议费(元)</label>
								<div class="layui-input-inline">
									<input th:value="*{costConf}" type="text" name="costConf" autocomplete="off" placeholder="会议费" class="layui-input">
								</div>

								<label class="layui-form-label">设备费(元)</label>
								<div class="layui-input-inline">
									<input th:value="*{costDevice}" type="text" name="costDevice" autocomplete="off" placeholder="设备费" class="layui-input">
								</div>

							</div>

											
							<div class="layui-form-item">
			                    <label class="layui-form-label">打印费(元)</label>
			                    <div class="layui-input-inline">
			                        <input th:value="*{costPrint}" type="text" name="costPrint" autocomplete="off" placeholder="打印费" class="layui-input">
			                    </div>

								<label class="layui-form-label">咨询费(元)</label>
								<div class="layui-input-inline">
									<input th:value="*{costConsult}" type="text" name="costConsult" autocomplete="off" placeholder="咨询费" class="layui-input">
								</div>

								<label class="layui-form-label">其他经费(元)</label>
								<div class="layui-input-inline">
									<input th:value="*{costOther}" type="text" name="costOther" autocomplete="off" placeholder="其他经费" class="layui-input">
								</div>

								<label class="layui-form-label">总费用(元)</label>
								<div class="layui-input-inline">
									<input th:value="*{costTotal}" type="text" name="costTotal" autocomplete="off" placeholder="预计总费用" class="layui-input">
								</div>

			                </div>

											
							<div class="layui-form-item">
			                    <label class="layui-form-label">单位账号</label>
			                    <div class="layui-input-inline">
			                        <input readonly th:value="*{costAccount}" style="width: 300px" type="text" name="costAccount" autocomplete="off" placeholder="经费单位账号" class="layui-input">
			                    </div>

								<label class="layui-form-label" style="margin-left: 80px">单位地址</label>
								<div class="layui-input-inline">
									<input readonly th:value="*{costAddress}" style="width: 300px" type="text" name="costAddress" autocomplete="off" placeholder="经费单位地址" class="layui-input">
								</div>

								<label class="layui-form-label" style="margin-left: 80px">单位邮编</label>
								<div class="layui-input-inline">
									<input readonly th:value="*{costZip}" type="text" name="costZip" autocomplete="off" placeholder="经费单位邮政编码" class="layui-input">
								</div>
			                </div>

							<div class="layui-form-item">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">
									<input th:value="*{costRemark}" type="text" name="costRemark" autocomplete="off" placeholder="备注" class="layui-input">
								</div>
							</div><br><br><br>

		<div class="layui-input-inline layui-hide">
			<input th:value="*{proType}" style="width: 300px" id="proType2" type="text" name="proType2" class="layui-input">
		</div>

</div>
</div>
	<div class="bottom" style="position: fixed;bottom: 0">
		<div class="button-container">

			<button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
				<i class="layui-icon layui-icon-ok"></i>
				保存
			</button>

			<button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="applyProject-update">
				<i class="layui-icon layui-icon-ok"></i>
				提交
			</button>
			<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
				<i class="layui-icon layui-icon-refresh"></i>
				重置
			</button>
		</div>
	</div>

</form>

<script>
	function start(){
		if($("#proType").val() == "b"){
			$("#selectChild").show();
			form.render();
		}else if($("#proType").val() == "a"){
			$("#selectChild").hide();
		}
	}
</script>

<script type="text/html" id="applyParticipator-toolbar">
	<button type="button" shiro:hasPermission="gen:applyParticipator:add" class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		<i class="layui-icon layui-icon-add-1"></i>
		新增
	</button>
	<button type="button" shiro:hasPermission="gen:applyParticipator:remove" class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		<i class="layui-icon layui-icon-delete"></i>
		删除
	</button>
</script>
<script type="text/html" id="applyParticipator-bar">
	<button type="button" shiro:hasPermission="gen:applyParticipator:edit" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>
	</button>

	<button type="button" shiro:hasPermission="gen:applyParticipator:remove" class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>
	</button>
</script>

<!--分工情况-->
<script type="text/html" id="applyTask-toolbar">
	<button type="button" shiro:hasPermission="gen:applyTask:add" class="pear-btn pear-btn-primary pear-btn-md" lay-event="add2">
		<i class="layui-icon layui-icon-add-1"></i>
		新增
	</button>
	<button type="button" shiro:hasPermission="gen:applyTask:remove" class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove2">
		<i class="layui-icon layui-icon-delete"></i>
		删除
	</button>
</script>

<script type="text/html" id="applyTask-bar">

	<button type="button" shiro:hasPermission="gen:applyTask:edit" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit2" title="修改"><i class="layui-icon layui-icon-edit"></i>
	</button>

	<button type="button" shiro:hasPermission="gen:applyTask:remove" class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove2" title="删除"><i class="layui-icon layui-icon-delete"></i>
	</button>
</script>



<th:block th:include="include :: footer"/>
<script>
    layui.use(['form','laydate','jquery','table','layedit'], function () {
		let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = rootPath+"/ApplyProjectController";
		var layedit=layui.layedit;

		//完成本课题条件论证提示
		$("#tjTips").mouseover(function() {
			layer.tips('包括参加人员的研究能力、资料设备、科研手段和时间保证等', this, {
				tips: [3, "#170c0c"],time:6000,
			});
		});

		//课题论证提示
		$("#lzTips").mouseover(function() {
			layer.tips('1.本课题国内外或省内外研究概况，本课题研究的理论意义。</br>' +
					'2.本课题研究的主要观点、主要内容、篇章结构、重点和难点分析。</br>' +
					'3.本课题的研究方法，预期研究成果。逐项填写，篇幅不够可加另项', this, {
				tips: [3, "#170c0c"],time:6000,
			});
		});

		//课题有关近期研究成果提示
		$("#ktTips").mouseover(function() {
			layer.tips('近期研究成果应注明成果名称、成果形式、发表刊物或出版单位，发表或出版时间', this, {
				tips: [3, "#170c0c"],time:6000,
			});
		});

		//项目类型显示或隐藏
		form.on('select(firstProType)', function(data){
			// console.log($("#proType option:selected").val());
			if($("#proType option:selected").val() == "b" ){
				$("#selectChild").show();
				form.render('select');
			}else{
				$("#selectChild").hide();
				form.render('select');//select是固定写法 不是选择器
			}
			form.render();
		});


		//配置近期研究成果的富文本编辑器
		// var layeditProResearch=layedit.build('proResearch',
		// 		{
		// 			tool: [
		// 				// 'strong' //加粗
		// 				// ,'italic' //斜体
		// 				// ,'underline' //下划线
		// 				// ,'del' //删除线
		// 				//
		// 				// ,'|' //分割线
		//
		// 				,'left' //左对齐
		// 				,'center' //居中对齐
		// 				,'right' //右对齐
		// 			]
		// 		}); //建立编辑器
		// //配置课题论证设计的富文本编辑器
		// var layeditProDesign=layedit.build('proDesign',
		// 		{
		// 			tool: [
		// 				// 'strong' //加粗
		// 				// ,'italic' //斜体
		// 				// ,'underline' //下划线
		// 				// ,'del' //删除线
		// 				//
		// 				// ,'|' //分割线
		//
		// 				,'left' //左对齐
		// 				,'center' //居中对齐
		// 				,'right' //右对齐
		// 			]
		// 		}); //建立编辑器
		//配置条件分析的富文本编辑器
		// var layeditProAnalyse=layedit.build('proAnalyse',
		// 		{
		// 			tool: [
		// 				// 'strong' //加粗
		// 				// ,'italic' //斜体
		// 				// ,'underline' //下划线
		// 				// ,'del' //删除线
		// 				//
		// 				// ,'|' //分割线
		//
		// 				,'left' //左对齐
		// 				,'center' //居中对齐
		// 				,'right' //右对齐
		// 			]
		// 		}); //建立编辑器

		//课题主要参与者而table字段
		let cols = [
			[
				{type: 'checkbox'},
				{title: '序号', type: 'numbers'},
				{title: '姓名', field: 'partName', align: 'center'},

				{title: '年龄', field: 'partAge', align: 'center'},

				{title: '专业职称', field: 'partTitle', align: 'center'},

				{title: '工作单位', field: 'partDept', align: 'center'},

				{title: '研究专长', field: 'partExpertise', align: 'center'},
				{title: '负责人', field: 'manName', align: 'center'},

				{title: '近期研究成果', field: 'researchRes', align: 'center'},

				{title: '操作', toolbar: '#applyParticipator-bar', align: 'center'}
			]
		]



		//参与者基本信息table表单列表
		table.render({
			elem: '#applyParticipator-table',
			url: rootPath+"/ApplyParticipatorController/" + 'list/'+$("input[name='proId']").val(),      //此处跳转到ApplyParticipatorController
			page: true,
			method: 'get',
			cols: cols,
			skin: 'line',
			toolbar: '#applyParticipator-toolbar',
			defaultToolbar: [{
				layEvent: 'refresh',
				icon: 'layui-icon-refresh',
			}, 'filter']
		});

		//table图标事件绑定
		table.on('tool(applyParticipator-table)', function (obj) {
			if (obj.event === 'remove') {
				window.remove(obj);
			} else if (obj.event === 'edit') {
				window.edit(obj);
			}
		});

		//table工具栏绑定
		table.on('toolbar(applyParticipator-table)', function (obj) {
			if (obj.event === 'add') {
				window.add();
			} else if (obj.event === 'refresh') {
				window.refresh();
			} else if (obj.event === 'batchRemove') {
				window.batchRemove(obj);
			}
		});

		//添加
		window.add = function () {
			var proId = $("input[name='proId']").val();
			layer.open({
				type: 2,
				title: '新增',
				shade: 0.1,
				area: ['500px', '500px'],
				content: rootPath+"/ApplyParticipatorController/" + 'add',
				success: function(layero, index){
					var body = layer.getChildFrame('body',index);//建立父子联系【核心语句】
					var iframeWin = window[layero.find('iframe')[0]['name']];//【核心句】
					// console.log(body);
					// iframeWin.method();   //这句话的意思是可以通过ifarmeWin调用子页面的方法
					var inputList = body.find('input');     //取得子页面中input输入框
					//将父页项目ID传给子页面
					body.find(inputList[0]).val(proId);
				}
			});
		}

		//修改
		window.edit = function (obj) {
			layer.open({
				type: 2,
				title: '修改',
				shade: 0.1,
				area: ['500px', '500px'],
				content: rootPath+"/ApplyParticipatorController/" + 'edit/' + obj.data['id']
			});

		}
		//删除
		window.remove = function (obj) {
			layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url: rootPath+"/ApplyParticipatorController/" + "remove?ids=" + obj.data['id'],
					dataType: 'json',
					type: 'delete',
					success: function (result) {
						layer.close(loading);
						if (result.code==200) {
							layer.msg(result.msg, {icon: 1, time: 1000}, function () {
								obj.del();
							});
						} else {
							layer.msg(result.msg, {icon: 2, time: 1000});
						}
					}
				})
			});
		}

		//批量删除
		window.batchRemove = function (obj) {
			let data = table.checkStatus(obj.config.id).data;
			if (data.length === 0) {
				layer.msg("未选中数据", {icon: 3, time: 1000});
				return false;
			}
			let ids = "";
			for (let i = 0; i < data.length; i++) {
				ids += data[i].id + ",";
			}
			ids = ids.substr(0, ids.length - 1);
			layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url: rootPath+"/ApplyParticipatorController/" + "remove?ids=" + ids,
					dataType: 'json',
					type: 'delete',
					success: function (result) {
						layer.close(loading);
						if (result.code==200) {
							layer.msg(result.msg, {icon: 1, time: 1000}, function () {
								table.reload('applyParticipator-table');
							});
						} else {
							layer.msg(result.msg, {icon: 2, time: 1000});
						}
					}
				})
			});
		}

		//刷新按钮
		window.refresh = function () {
			table.reload('applyParticipator-table');
		}

		//分工情况table字段
		let cols2 = [
			[
				{type: 'checkbox'},

				{title: '序号', type: 'numbers'},

				{title: '承担人', field: 'partName', align: 'center'},

				{title: '研究开始时间', field: 'dateStart', align: 'center'},

				{title: '最终完成时间', field: 'dateEnd', align: 'center'},

				{title: '阶段成果名称', field: 'resName', align: 'center'},

				{title: '最终成果形式', field: 'resType', align: 'center'},

				{title: '操作', toolbar: '#applyTask-bar', align: 'center'}
			]
		]

		//分工情况table表单列表
		table.render({
			elem: '#applyTask-table',
			url: rootPath+"/ApplyTaskController/" + 'list/'+$("input[name='proId']").val(),
			page: true,
			method: 'get',
			cols: cols2,
			skin: 'line',
			toolbar: '#applyTask-toolbar',
			defaultToolbar: [{
				layEvent: 'refresh',
				icon: 'layui-icon-refresh',
			}, 'filter']
		});

		//分工情况table图标事件绑定
		table.on('tool(applyTask-table)', function (obj) {
			if (obj.event === 'remove2') {
				window.remove2(obj);
			} else if (obj.event === 'edit2') {
				window.edit2(obj);
			}
		});

		//分工情况table工具栏绑定
		table.on('toolbar(applyTask-table)', function (obj) {
			if (obj.event === 'add2') {
				window.add2();
			} else if (obj.event === 'refresh2') {
				window.refresh2();
			} else if (obj.event === 'batchRemove2') {
				window.batchRemove2(obj);
			}
		});

		//添加
		window.add2 = function () {
			var proId = $("input[name='proId']").val();
			layer.open({
				type: 2,
				title: '新增',
				shade: 0.1,
				area: ['500px', '500px'],
				content: rootPath+"/ApplyTaskController/" + 'add',
				success: function(layero, index){
					var body = layer.getChildFrame('body',index);//建立父子联系【核心语句】
					var iframeWin = window[layero.find('iframe')[0]['name']];//【核心句】
					// console.log(body);
					// iframeWin.method();   //这句话的意思是可以通过ifarmeWin调用子页面的方法
					var inputList = body.find('input');     //取得子页面中input输入框
					//将父页项目ID传给子页面
					body.find(inputList[0]).val(proId);
				}
			});
		}
		//修改
		window.edit2 = function (obj) {
			layer.open({
				type: 2,
				title: '修改',
				shade: 0.1,
				area: ['500px', '500px'],
				content: rootPath+"/ApplyTaskController/" + 'edit/' + obj.data['id']
			});
		}
		//删除
		window.remove2 = function (obj) {
			layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url: rootPath+"/ApplyTaskController/" + "remove?ids=" + obj.data['id'],
					dataType: 'json',
					type: 'delete',
					success: function (result) {
						layer.close(loading);
						if (result.code==200) {
							layer.msg(result.msg, {icon: 1, time: 1000}, function () {
								obj.del();
							});
						} else {
							layer.msg(result.msg, {icon: 2, time: 1000});
						}
					}
				})
			});
		}

		//批量删除
		window.batchRemove2 = function (obj) {
			let data = table.checkStatus(obj.config.id).data;
			if (data.length === 0) {
				layer.msg("未选中数据", {icon: 3, time: 1000});
				return false;
			}
			let ids = "";
			for (let i = 0; i < data.length; i++) {
				ids += data[i].id + ",";
			}
			ids = ids.substr(0, ids.length - 1);
			layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url: rootPath+"/ApplyTaskController/" + "remove?ids=" + ids,
					dataType: 'json',
					type: 'delete',
					success: function (result) {
						layer.close(loading);
						if (result.code==200) {
							layer.msg(result.msg, {icon: 1, time: 1000}, function () {
								table.reload('applyTask-table');
							});
						} else {
							layer.msg(result.msg, {icon: 2, time: 1000});
						}
					}
				})
			});
		}


		//刷新按钮
		window.refresh2 = function () {
			table.reload('applyTask-table');
		}

		//保存
		form.on('submit(save)', function (data) {


			//状态为待审核
			// data.field.proState = 0;
			//富文本
			// data.field.proResearch = layedit.getContent(layeditProResearch);
			// data.field.proDesign = layedit.getContent(layeditProDesign);
			// data.field.proAnalyse = layedit.getContent(layeditProAnalyse);

			data.field.proType = $("#proType option:selected").val();
			data.field.manSex = $("input[name='manSex']:checked").val();
			data.field.proSubject = $("#proSubject option:selected").val();
			data.field.id = $("#proId").val();

			if($("#proType option:selected").val() == "b" && $("#shengType").val() == ""){
				layer.msg("请选择省级子项目类型");
				return false;
			}
			if($("#shengType").val() != ""){
				data.field.proTypeChild = $("#shengType option:selected").val();
			}
			if($("#shengType").val() == ""){
				data.field.proTypeChild ="a";
			}
			let loader = layer.load();
			$.ajax({
				url: MODULE_PATH+'/editSave',
				data: data.field,
				dataType: 'json',
				contentType: 'application/x-www-form-urlencoded',
				type: 'post',
				success: function (result) {
					if (result.code==200) {
						layer.msg(result.msg, {icon: 1, time: 1000}, function () {
							parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
							parent.layui.table.reload("applyProject-table");
							layer.close(loader);
						});
					} else {
						layer.msg(result.msg, {icon: 2, time: 1000});
						layer.close(loader);
					}
				}
			})
			return false;
		});


        //更新
		form.on('submit(applyProject-update)', function (data) {
			data.field.proType = $("#proType option:selected").val();
			data.field.manSex = $("input[name='manSex']:checked").val();
			data.field.proSubject = $("#proSubject option:selected").val();
			data.field.id = $("#proId").val();
			//富文本
			// data.field.proResearch = layedit.getContent(layeditProResearch);
			// data.field.proDesign = layedit.getContent(layeditProDesign);
			// data.field.proAnalyse = layedit.getContent(layeditProAnalyse);
			//项目状态变更为审核中

			//省级项目选择提示
			if($("#proType option:selected").val() == "b" && $("#shengType").val() == ""){
				layer.msg("请选择省级子项目类型");
				return false;
			}
			if($("#shengType").val() != ""){
				data.field.proTypeChild = $("#shengType option:selected").val();
			}
			if($("#shengType").val() == ""){
				data.field.proTypeChild = "a";
			}
			layer.confirm('确定要提交信息，提交后将无法更改', {icon: 3, title: '提示'}, function (index) {
			let loader = layer.load();
			$.ajax({
				url: MODULE_PATH+'/edit',
				data: data.field,
				dataType: 'json',
				contentType: 'application/x-www-form-urlencoded',
				type: 'post',
				success: function (result) {
					if (result.code==200) {
						layer.msg(result.msg, {icon: 1, time: 1000}, function () {
							parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
							parent.layui.table.reload("applyProject-table");
							layer.close(loader);
						});
					} else {
						layer.msg(result.msg, {icon: 2, time: 1000});
						layer.close(loader);
					}
				}
				})
			});
			return false;
		});
    })
</script>
</body>
</html>